package com.atguigu.lease.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

//mybatis-plus中的自动填充处理器,用自动填充createTime和updateTime
@Component
public class StgyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.hasGetter("createTime")) {
            metaObject.setValue("createTime", new Date());
        }
        if (metaObject.hasGetter("updateTime")) {
            metaObject.setValue("updateTime", new Date());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasGetter("updateTime")) {
            metaObject.setValue("updateTime", new Date());
        }
    }
}
